<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/7 0007
 * Time: 20:01
 */
class person
{
    public $name;
    public $gender;
    public $age;

    public function say()
    {
        echo $this->name, " \tis ", $this->gender, "\r\n";
    }

    public function set($name, $value)
    {
        echo "Setting $name to $value \r\n";
        $this->$name = $value;
    }

    public function get($name)
    {
        if (!isset($this->$name)) {
            echo '未设置';

            $this->$name = "正在为你设置默认值";
        }
        return $this->$name;
    }
}

$student = new person();
$student->name = 'Tom';
$student->gender = 'male';
//$student->age = 24;
$reflect = new ReflectionObject($student);
//获取对象的属性
$props = $reflect->getProperties();
foreach ($props as $index => $prop) {
//    echo $prop->getName() . "\n";
}
//获得对象方法列表
$methods = $reflect->getMethods();
foreach ($methods as $method) {
//    echo $method->getName() . "\n";
}
//获取对象属性的关联数组
//var_dump(get_object_vars($student));
//获得类属性
//var_dump(get_class_vars(get_class($student)));
//返回由类的方法组成的数组
var_dump(get_class_methods(get_class($student)));
